package project;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import javax.swing.SwingConstants;
import java.awt.Font;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;

public class Test_Details {

	public JFrame frame;
	public JTextArea inst;
	public JTextField textField;
	public JButton btnProceed;
	public JButton btnBack;
	public JButton btnNext;
	public int counter = 0;
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Test_Details window = new Test_Details();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	
	public Test_Details() {
		initialize();
	}

	
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 700, 500);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JLabel lblInstructionsForThe = new JLabel("Instructions for the Test");
		lblInstructionsForThe.setFont(new Font("Tahoma", Font.BOLD, 18));
		lblInstructionsForThe.setHorizontalAlignment(SwingConstants.CENTER);
		lblInstructionsForThe.setBounds(10, 31, 648, 42);
		frame.getContentPane().add(lblInstructionsForThe);
		
		 inst = new JTextArea();
		inst.setText("Instruction 1.\r\n\r\n");
		inst.setBackground(UIManager.getColor("Button.background"));
		inst.setWrapStyleWord(true);
		inst.setLineWrap(true);
		inst.setEditable(false);
		inst.setBounds(62, 149, 560, 223);
		frame.getContentPane().add(inst);
		
		btnProceed = new JButton("Proceed");
		btnProceed.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent evt) {
					
					btnProceedActionPerformed(evt);
				}
			});	
			
		btnProceed.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnProceed.setBounds(298, 410, 111, 31);
		btnProceed.setVisible(false);
		frame.getContentPane().add(btnProceed);
		
		btnNext = new JButton("Next >>");
		btnNext.setFont(new Font("Tahoma", Font.BOLD, 12));
		btnNext.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				
				btnNextActionPerformed(evt);
			}
		});
		btnNext.setBounds(457, 415, 89, 23);
		frame.getContentPane().add(btnNext);
		
		JLabel lblWelcome = new JLabel("Welcome");
		lblWelcome.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblWelcome.setHorizontalAlignment(SwingConstants.CENTER);
		lblWelcome.setBounds(187, 106, 138, 23);
		frame.getContentPane().add(lblWelcome);
		
		textField = new JTextField();
		textField.setFont(new Font("Tahoma", Font.BOLD, 14));
		textField.setHorizontalAlignment(SwingConstants.CENTER);
		textField.setEditable(false);
		textField.setBounds(335, 98, 225, 40);
		frame.getContentPane().add(textField);
		textField.setColumns(10);
		
		btnBack = new JButton("<< Back");
		btnBack.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnBackActionPerformed(evt);
			}
		});
		
		
		btnBack.setFont(new Font("Tahoma", Font.BOLD, 12));
		btnBack.setBounds(157, 414, 89, 23);
		frame.getContentPane().add(btnBack);
		btnBack.setVisible(false);
	}
	
	public void display(String str)
	{
		textField.setText(str);
	}
	private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {
		
		counter = counter +1;
		
		if(counter == 1)
		{
			inst.setText("Instruction 2.\r\n\r\n");
			btnProceed.setVisible(false);
			btnNext.setVisible(true);
			btnBack.setVisible(true);
		
		}
		
		if(counter == 2)
		{
			inst.setText("Instruction 3.\r\n\r\n");
			btnProceed.setVisible(false);
			btnNext.setVisible(true);
			btnBack.setVisible(true);
		}
		if(counter == 3)
		{
			inst.setText("Instruction 4.\r\n\r\n");
			btnProceed.setVisible(true);
			btnNext.setVisible(false);
		}
		if(counter > 3)
		{
			counter = 0;
		}
				
	}
	
	private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {
		
		counter = counter - 1;
		
		if(counter == 0)
		{
			inst.setText("Instruction 1.\r\n\r\n");
			btnProceed.setVisible(false);
			btnNext.setVisible(true);
			btnBack.setVisible(false);
		}
		
		if(counter == 1)
		{
			inst.setText("Instruction 2.\r\n\r\n");
			btnProceed.setVisible(false);
			btnNext.setVisible(true);
			btnBack.setVisible(true);
		
		}
		
		if(counter == 2)
		{
			inst.setText("Instruction 3.\r\n\r\n");
			btnProceed.setVisible(false);
			btnNext.setVisible(true);
			btnBack.setVisible(true);
		}
		if(counter == 3)
		{
			inst.setText("Instruction 4.\r\n\r\n");
			btnProceed.setVisible(true);
			btnNext.setVisible(false);
		}	
		
		if(counter < 0)
		{
			counter = 0;
		}
	
	}
	
	private void btnProceedActionPerformed(java.awt.event.ActionEvent evt) {
		
		TestPaper tp = new TestPaper();
		tp.frame.setVisible(true);
		this.frame.setVisible(false);
	}
}
